import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import settingsRouter from './modules/settings'
import permissionRouter from './modules/permissions'
import socialRouter from './modules/social_securitys'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import approvalsRouter from './modules/approvals'
// 静态路由
export const constantRoutes = [
  // 登录
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 404
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },
  // 员工导入导出
  {
    path: '/import',
    component: Layout,
    hidden: true, // 不显示到左侧菜单
    children: [{
      path: '',
      component: () => import('@/views/import')
    }]
  }
  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]
// 动态路由
export const asyncRouters = [
  departmentsRouter, // 组织架构
  employeesRouter, // 员工管理
  settingsRouter, // 公司设置
  permissionRouter, // 权限管理
  socialRouter, // 社保管理
  attendancesRouter, // 考勤管理
  salarysRouter, // 工资管理
  approvalsRouter // 审批管理
]
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes]
  })

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
